//
//  UIImage+Color.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/4/13.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "UIImage+Color.h"

@implementation UIImage (Color)

+ (UIImage *)gradientImageWithColorArray:(NSArray *)colorArray beginPoint:(CGPoint)begin endPoint:(CGPoint)end rect:(CGRect)rect
{
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colorArray, NULL);
    CGContextDrawLinearGradient(ctx, gradient, begin, end, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    CGGradientRelease(gradient);
    CGColorSpaceRelease(colorSpace);
    UIGraphicsEndImageContext();
    return image;
}

@end
